package com.lbs.jiepiaisi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.bean.EquipmentEntity;
import com.lbs.jiepiaisi.bean.WeiZhangEntity;

import java.util.List;

/**
 *
 * 时间：2018/1/02 18:38
 * 作用：违章结果查询
 */

public class WeiZhangLineAdapter extends Adapter<ViewHolder> {
    private static final int TYPE_ITEM = 0;
    private static final int TYPE_FOOTER = 1;
    private Context context;
    List<WeiZhangEntity.Lists.Item> listItem;

    public WeiZhangLineAdapter(Context context, List<WeiZhangEntity.Lists.Item> listItem) {
        this.context = context;
        this.listItem = listItem;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemCount() {
        return listItem.size();
    }

    @Override
    public int getItemViewType(int position) {
        return TYPE_ITEM;
    }

    /**
     * 创建新View，被LayoutManager所调用
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_wei_zhang, parent,
                false);


        return new ItemViewHolder(view);
    }

    /**
     * 把现在的数据绑定到原有的viewHolder之上
     */
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {

        ((ItemViewHolder) holder).tv_time.setText(listItem.get(position).getDate());
        ((ItemViewHolder) holder).tv_title.setText(listItem.get(position).getAct());
        ((ItemViewHolder) holder).tv_area.setText(listItem.get(position).getArea());
        if("1".equals(listItem.get(position).getHandled())){
            ((ItemViewHolder) holder).tv_handled.setText("已处理");
        }else {
            ((ItemViewHolder) holder).tv_handled.setTextColor(context.getResources().getColor(R.color.blue));
            ((ItemViewHolder) holder).tv_handled.setText("未处理");
        }

        ((ItemViewHolder) holder).tv_money.setText("罚款" + listItem.get(position).getMoney() + "元");
        ((ItemViewHolder) holder).tv_fen.setText("扣" + listItem.get(position).getFen() + "分");

    }


    static class ItemViewHolder extends ViewHolder {
        TextView tv_time;
        TextView tv_title;
        TextView tv_area;
        TextView tv_handled;
        TextView tv_money;
        TextView tv_fen;

        public ItemViewHolder(View view) {
            super(view);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_area = (TextView) view.findViewById(R.id.tv_area);
            tv_handled = (TextView) view.findViewById(R.id.tv_handled);
            tv_money = (TextView) view.findViewById(R.id.tv_money);
            tv_fen = (TextView) view.findViewById(R.id.tv_fen);
        }
    }


}
